package com.ivc.info.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cs.framework.jdbc.common.dao.CommonDao;
import com.ivc.info.dto.base.StockDetailDto;
import com.ivc.info.service.StockDetailService;

/**
 * 库存明细
 * 
 * @author hedongzhou
 * 
 */
@Service("stockDetailService")
public class StockDetailServiceImpl implements StockDetailService {

	@Resource
	private CommonDao commonDao;

	/**
	 * 查询库存明细
	 * 
	 * @param detailNo
	 *            明细编号
	 * @return
	 */
	public StockDetailDto get(Long detailNo) {
		return commonDao.getById(StockDetailDto.class, detailNo);
	}

	/**
	 * 查询库存明细总数
	 * 
	 * @param stockDetailDto
	 * @return
	 */
	public int count(StockDetailDto stockDetailDto) {
		return commonDao.count("StockDetail.query", stockDetailDto);
	}

	/**
	 * 查询库存明细列表
	 * 
	 * @param stockDetailDto
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public <T extends StockDetailDto> List<T> query(T stockDetailDto) {
		return (List<T>) commonDao.selectList("StockDetail.query", stockDetailDto, stockDetailDto, stockDetailDto
				.getClass());
	}

	/**
	 * 根据供应商查询库存数量
	 * 
	 * @param stockNo
	 *            库存编号
	 * @param supplierNo
	 *            供应商编号
	 * @return
	 */
	public int sumQuanBySupplier(Long stockNo, String supplierNo) {
		StockDetailDto stockDetailDto = new StockDetailDto();
		stockDetailDto.setStockNo(stockNo);
		stockDetailDto.setSupplierNo(supplierNo);

		Integer sum = commonDao.selectOne("StockDetail.sumQuanBySupplier", stockDetailDto, Integer.class);
		return sum == null ? 0 : sum;
	}

	/**
	 * 新增库存明细
	 * 
	 * @param stockDetailDto
	 * @return
	 */
	public StockDetailDto save(StockDetailDto stockDetailDto) {
		return commonDao.save(stockDetailDto);
	}

}
